package com.ruoyi.recycle.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.ruoyi.recycle.domain.ShopManagement;
import com.ruoyi.recycle.vo.AttractRecordVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 引流门店管理Mapper接口
 *
 * @author Wubk
 * @date 2022-05-21
 */
public interface ShopManagementMapper extends BaseMapper<ShopManagement> {
    /**
     * 查询引流门店管理
     *
     * @param id 引流门店管理主键
     * @return 引流门店管理
     */
    public ShopManagement selectShopManagementById(Long id);

    /**
     * 查询引流门店管理列表
     *
     * @param shopManagement 引流门店管理
     * @return 引流门店管理集合
     */
    public List<ShopManagement> selectShopManagementList(ShopManagement shopManagement);

    /**
     * 新增引流门店管理
     *
     * @param shopManagement 引流门店管理
     * @return 结果
     */
    public int insertShopManagement(ShopManagement shopManagement);

    /**
     * 修改引流门店管理
     *
     * @param shopManagement 引流门店管理
     * @return 结果
     */
    public int updateShopManagement(ShopManagement shopManagement);

    /**
     * 删除引流门店管理
     *
     * @param id 引流门店管理主键
     * @return 结果
     */
    public int deleteShopManagementById(Long id);

    /**
     * 批量删除引流门店管理
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteShopManagementByIds(Long[] ids);


    List<ShopManagement> selectshopnear(@Param("minlat") double minlat, @Param("maxlat") double maxlat, @Param("minlng") double minlng, @Param("maxlng") double maxlng);

    List<ShopManagement> selectShopByName(@Param("minlat") double minlat, @Param("maxlat") double maxlat, @Param("minlng") double minlng, @Param("maxlng") double maxlng, @Param("name") String name, @Param("type") String type);


    List<ShopManagement> collectShopPageQuery(Long clientId);

    Long selectClientCollect(@Param("shopId") Long shopId, @Param("clientId") Long clientId);

    @Select("select s.shop_name as shopName,s.id as shop_id, s.salesman_id as salesmanId, s.salesman_name as salesmanName, count(c.id) as attractDay " +
            "from shop_management s " +
            "left join client_user_management c " +
            "on s.id = c.shop_id ${ew.customSqlSegment}")
    public List<AttractRecordVO> attractDayStatics(@Param(Constants.WRAPPER) LambdaQueryWrapper wrapper);

    @Select("select s.id   count(c.id) as attractMonth " +
            "from shop_management s " +
            "left join client_user_management c " +
            "on s.id = c.shop_id ${ew.customSqlSegment}")
    public List<Map<Long, Integer>> attractMonthStatics(@Param(Constants.WRAPPER) LambdaQueryWrapper wrapper);

}
